package com.yuanye.gwcit.fragments;

import android.graphics.Color;

import com.yuanye.gwcit.GW;
import com.yuanye.yeecho.base.CommonTaskFragment;
import com.yuanye.yeecho.utils.YY;

public class RamCheckFragment extends CommonTaskFragment {

    public RamCheckFragment() {
        setTaskName("内存检测");
    }

    @Override
    public void execTask() {
        super.execTask();
        String[] cmds = {"sh", "-c", "cat /proc/meminfo | awk 'NR==1 {print$2}'"};
//        String info = YY.execShell("cat /proc/meminfo");
        String info = YY.execShell(cmds);
        if(info.isEmpty()){
            appendLogF("未获取到内存信息");
            setFail();
            return;
        }
        String stdSizeStr = GW.cfgPcba.getRamSize();
        double stdSize = Double.parseDouble(stdSizeStr);
        double size = Double.parseDouble(info) /1024/1024;
        double roundSize = Double.parseDouble(String.format("%.2f", size));
//        DecimalFormat df = new DecimalFormat("#0.00");
//        String dfSize =  df.format(size);
        appendLog("内存大小："+roundSize);
        appendLog("参考数值："+stdSizeStr);
        double deltaSize = Math.abs(stdSize - roundSize);
        if (deltaSize <= 0.2){
            appendLog("内存检测通过");
            passAndNext();
        }else{
            setFail();
        }
    }
}
